package com.cheung.leetcode.normal;

import java.util.ArrayList;
import java.util.List;

public class LC46 {

    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        backtracking(result, path, nums);
        return result;
    }

    private static void backtracking(List<List<Integer>> result, List<Integer> path, int[] nums) {
        if (path.size() == nums.length) {
            result.add(new ArrayList<>(path));
            return;
        }


        for (int num : nums) {
            if (!path.contains(num)) {
                path.add(num);
                backtracking(result, path, nums);
                path.remove(path.size() - 1);
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        System.out.println(permute(nums));
    }
}
